// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/AlarmApi'

import EditClass from '@api/base/model/AlarmDealReq'
import MultiClass from '@api/base/model/AlarmBatchDealReq'
import BaseClass from '@api/base/model/MessageAlarmDto'
import FileClass from '@api/base/model/MessageAlarmFileDto'

const CLIENT = CORE.grpcCLIENT(Client)
const BASE = [BaseClass, 'content', null, (dto, obj) => {
  const imageList = obj.image.map((fileUrl) => ({ fileUrl, fileName: fileUrl.split('/').pop(), fileType: 1 }))
  CORE.grpcDTO(dto, obj, [FileClass, 'messageAlarmDealFileDto', imageList])
}]

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 修改 —————————————————————————————— //

  async edit(one, TIP = '修改') {
    if (one.id) {
      const DTO = CORE.grpcDTO(EditClass, one, BASE)
      await CORE.grpc(TIP, CLIENT, 'deal', DTO)
    }
    if (CORE.isArray(one.ids) && one.ids.length) {
      const DTO = CORE.grpcDTO(MultiClass, one, BASE)
      await CORE.grpc(TIP, CLIENT, 'batchDeal', DTO)
    }
    return CORE.grpcOK(TIP)
  },
}
